<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    public function run() {
        
        $config = $this->getOptions();
        Zend_Registry::set('config', new Zend_Config($config));
        Zend_Registry::set('settings', $this->_getSettings());
        parent::run();
    }

    private function _getSettings() {

        $settings = new Zend_Config_Ini(APPLICATION_PATH . '/configs/settings.ini');
        return $settings;
    }

    protected function _initDbCache() {

        $settings = $this->_getSettings();

        if ($settings->cache->datos) {

                $this->bootstrap('db');
                $this->bootstrap('cachemanager');
                $cache = $this->getResource('cachemanager');
                Zend_Db_Table_Abstract::setDefaultMetadataCache($cache->getCache('database'));
        }
    }

    public function _initView() {

        $settings = $this->_getSettings();

        if ($settings->cache->vistas) {

                $frontendOptions = array(
                    'debug_header' => false, //false,true
                    'regexps' => array(
                        '^/' => array(
                            'cache' => true,
                            'cache_with_cookie_variables' => true,
                        )
                    ),
                    'memorize_headers' => array(
                        'Content-Type',
                        'Content-Encoding',
                        'Accept-Encoding'
                    )
                );

                $backendOptions = array(
                    'cache_dir' => APPLICATION_PATH . '/cache/views'
                );

                $cache = Zend_Cache::factory(
                                'Page',
                                'File',
                                $frontendOptions,
                                $backendOptions
                );

                $cache->start();
        }
    }

    protected function _initAppAutoload() {
        $autoloader = new Zend_Application_Module_Autoloader(array(
                    'namespace' => 'Application',
                    'basePath' => APPLICATION_PATH,
                ));

        return $autoloader;
    }

    protected function _initViewHelpers() {

        $this->bootstrap('layout');
        $layout = $this->getResource('layout');
        $view = $layout->getView();
        $view->doctype('XHTML1_TRANSITIONAL');
        $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8');
    }

    protected function _initTranslator() {

        $translator = new Zend_Translate(
                        'array',
                        APPLICATION_PATH . '/../resources/languages',
                        'es',
                        array('scan' => Zend_Translate::LOCALE_DIRECTORY));

        Zend_Validate_Abstract::setDefaultTranslator($translator);
        Zend_Form::setDefaultTranslator($translator);
    }

}